﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using ENICHIUSURA.Utils;
using Logging;
using System.Data;

namespace ENICHIUSURA.Tests
{
    // Testing class ()
    // TO DO Nunit Testing
    class EniTesting
    {
        public static string inputFilePath = ConfigurationManager.AppSettings["InputFilePath"];
        public static string inputFilename = ConfigurationManager.AppSettings["InputFileName"];

        public static string outputFilepath = ConfigurationManager.AppSettings["OutputFilePath"];
        public static string outputFileName = ConfigurationManager.AppSettings["OutputFilename"];

        //test entire automation process
        public static void AutomationTest()
        {
            Automation au = new Automation();
            if (au.Run(ExcelUtils.GetExcelDT(inputFilePath, inputFilename)) == "OK")//excel file written
            {
                MailUtils.SendMail(ConfigurationManager.AppSettings["Sender"],
                                    ConfigurationManager.AppSettings["StatusEmail"],
                                    "AGOS IMPORTO SINGOLE RATA " + DateTime.Now.ToShortDateString(),
                                    "AGOS prelievo dell’importo della singola rata : " + DateTime.Now.ToShortDateString(),
                                     ConfigurationManager.AppSettings["OutputFilePath"] + ConfigurationManager.AppSettings["OutputFileName"]);
            }
            else
            {
                Logger.LogInfo("Excel file not exported");
            }
        }

        public static void ReadExcelTest(string path, string filename)
        {
            object[,] cells = ExcelUtils.ReadExcel(path, filename);
        }

        public static void ArrayToDTTest(string path, string filename)
        {
            object[,] cells = ExcelUtils.ReadExcel(path, filename);
            DataTable dt = ExcelUtils.ArrayToDT(cells); // Nunit test may look like Assert.AreEqual(cells.rows,dt.rows.count)
        }

        public static void ExportDtToExcel(string path, string filename)
        {
            object[,] cells = ExcelUtils.ReadExcel(EniTesting.inputFilePath, EniTesting.inputFilename);
            DataTable dt = ExcelUtils.ArrayToDT(cells); // Nunit test may look like Assert.AreEqual(cells.rows,dt.rows.count)
            ExcelUtils.ExportDtToExcel(EniTesting.outputFilepath, dt, EniTesting.outputFileName);
        }

        public static void RenameOutputFile(string fileName)
        {
            string name = FileUtils.AppendDateToFileName(fileName);
        }
    }
}
